package com.hoshino.momochi.config.websocket;

import com.hoshino.momochi.annotation.IgnoreLogin;
import com.hoshino.momochi.config.websocket.WebSocketServer;
import com.hoshino.momochi.util.JsonResponse;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RestController
public class WebSocketController {
    //推送数据接口
    @RequestMapping("/socket/push/{cid}")
    @IgnoreLogin
    public JsonResponse pushToWeb(@PathVariable String cid, String message) {
        Map<String, Object> result = new HashMap<>();
        try {
            WebSocketServer.sendInfo(message, cid);
            result.put("code", cid);
            result.put("msg", message);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return JsonResponse.success(result);
    }
}
